<?php
require_once("mysql.inc.php");

if(isset($_GET["a"])) {
	getThemes();
}

function getThemes() {

	$result = mysql_query("SELECT * FROM `themes` ORDER BY `name`");
	$num = mysql_num_rows($result);
	$i = 1;
	
	//create new dom document
	$doc = new DomDocument('1.0');
	$root = $doc->createElement("results");
	$doc->appendChild($root);
	
	//create first element containing amount of results
	$n = $doc->createElement("num");
	$n->appendChild($doc->createTextNode($num));
	$root->appendChild($n);
	
	while($fetch = mysql_fetch_array($result)) {
		
		$g = $doc->createElement("theme$i");
		$g->appendChild($doc->createTextNode($fetch["name"]));
		$root->appendChild($g);
		
		$i++;
	}
	
	echo $doc->saveXML();
}
?>